use SiteStore;
use WatchedItemStore;
use SkinFactory;
+use TitleFormatter;
+use TitleParser;
/**
* Service locator for MediaWiki core services.
public function getGenderCache() {
return $this->getService( 'GenderCache' );
}
+ /**
+ * @since 1.28
+ * @return TitleFormatter
+ */
+ public function getTitleFormatter() {
+ return $this->getService( 'TitleFormatter' );
+ }
+
+ /**
+ * @since 1.28
+ * @return TitleParser
+ */
+ public function getTitleParser() {
+ return $this->getService( 'TitleParser' );
+ }
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service getter here, don't forget to add a test
return new GenderCache();
},
+ '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
+ global $wgContLang;
+
+ return new MediaWikiTitleCodec(
+ $wgContLang,
+ $services->getGenderCache(),
+ $services->getMainConfig()->get( 'LocalInterwikis' )
+ );
+ },
+
+ 'TitleFormatter' => function( MediaWikiServices $services ) {
+ return $services->getService( '_MediaWikiTitleCodec' );
+ },
+
+ 'TitleParser' => function( MediaWikiServices $services ) {
+ return $services->getService( '_MediaWikiTitleCodec' );
+ },
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service here, don't forget to add a getter function
// in the MediaWikiServices class. The convenience getter should just call
* @file
*/
use MediaWiki\Linker\LinkTarget;
-
use MediaWiki\MediaWikiServices;
/**
private $mIsBigDeletion = null;
// @}
- /**
- * B/C kludge: provide a TitleParser for use by Title.
- * Ideally, Title would have no methods that need this.
- * Avoid usage of this singleton by using TitleValue
- * and the associated services when possible.
- *
- * @return MediaWikiTitleCodec
- */
- private static function getMediaWikiTitleCodec() {
- global $wgContLang, $wgLocalInterwikis;
-
- static $titleCodec = null;
- static $titleCodecFingerprint = null;
-
- // $wgContLang and $wgLocalInterwikis may change (especially while testing),
- // make sure we are using the right one. To detect changes over the course
- // of a request, we remember a fingerprint of the config used to create the
- // codec singleton, and re-create it if the fingerprint doesn't match.
- $fingerprint = spl_object_hash( $wgContLang ) . '|' . implode( '+', $wgLocalInterwikis );
-
- if ( $fingerprint !== $titleCodecFingerprint ) {
- $titleCodec = null;
- }
-
- if ( !$titleCodec ) {
- $titleCodec = new MediaWikiTitleCodec(
- $wgContLang,
- GenderCache::singleton(),
- $wgLocalInterwikis
- );
- $titleCodecFingerprint = $fingerprint;
- }
-
- return $titleCodec;
- }
-
/**
* B/C kludge: provide a TitleParser for use by Title.
* Ideally, Title would have no methods that need this.
* @return TitleFormatter
*/
private static function getTitleFormatter() {
- // NOTE: we know that getMediaWikiTitleCodec() returns a MediaWikiTitleCodec,
- // which implements TitleFormatter.
- return self::getMediaWikiTitleCodec();
+ return MediaWikiServices::getInstance()->getTitleFormatter();
}
function __construct() {
// @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
// the parsing code with Title, while avoiding massive refactoring.
// @todo: get rid of secureAndSplit, refactor parsing code.
- $titleParser = self::getMediaWikiTitleCodec();
+ // @note: getTitleParser() returns a TitleParser implementation which does not have a
+ // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
+ $titleCodec = MediaWikiServices::getInstance()->getTitleParser();
// MalformedTitleException can be thrown here
- $parts = $titleParser->splitTitleString( $dbkey, $this->getDefaultNamespace() );
+ $parts = $titleCodec->splitTitleString( $dbkey, $this->getDefaultNamespace() );
# Fill fields
$this->setFragment( '#' . $parts['fragment'] );
* @file
* @ingroup Testing
*/
+use MediaWiki\MediaWikiServices;
/**
* @ingroup Testing
Hooks::clear( 'InterwikiLoadPrefix' );
}
+ /**
+ * Reset the Title-related services that need resetting
+ * for each test
+ */
+ public static function resetTitleServices() {
+ $services = MediaWikiServices::getInstance();
+ $services->resetServiceForTesting( 'TitleFormatter' );
+ $services->resetServiceForTesting( 'TitleParser' );
+ $services->resetServiceForTesting( '_MediaWikiTitleCodec' );
+
+ }
+
public function setupRecorder( $options ) {
if ( isset( $options['record'] ) ) {
$this->recorder = new DbTestRecorder( $this );
MWTidy::destroySingleton();
RepoGroup::destroySingleton();
+ self::resetTitleServices();
+
return $context;
}
// All getters should be named just like the service, with "get" added.
foreach ( $getServiceCases as $name => $case ) {
+ if ( $name[0] === '_' ) {
+ // Internal service, no getter
+ continue;
+ }
list( $service, $class ) = $case;
$getterCases[$name] = [
'get' . $service,
'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer' ],
'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ],
'GenderCache' => [ 'GenderCache', GenderCache::class ],
+ '_MediaWikiTitleCodec' => [ '_MediaWikiTitleCodec', MediaWikiTitleCodec::class ],
+ 'TitleFormatter' => [ 'TitleFormatter', TitleFormatter::class ],
+ 'TitleParser' => [ 'TitleParser', TitleParser::class ],
];
}
]
]
] );
+
+ // Reset TitleParser since we modified $wgLocalInterwikis
+ $this->setService( 'TitleParser', new MediaWikiTitleCodec(
+ Language::factory( 'en' ),
+ new GenderCache(),
+ [ 'localtestiw' ]
+ ) );
}
/**
<?php
-
/**
* Although marked as a stub, can work independently.
*
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
$wgContLang->resetNamespaces(); # reset namespace cache
+ ParserTest::resetTitleServices();
}
protected function tearDown() {